/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ModelView.java
 *
 * Created on 2011-12-04, 23:46:28
 */
package phongmodel;

import java.awt.Color;
import java.awt.Graphics;
import java.text.DecimalFormat;
import java.text.Format;

/**
 *
 * @author Apapus
 */
public class ModelView extends javax.swing.JPanel {

    /** Creates new form ModelView */
    public ModelView() {
        initComponents();
        sphere = new MySphere(new Point3D(0,0,0), 150);
        light = new Light(new Point3D(0,50,300));
        cam = new MyCamera(new Point3D(0,0,300));
        initTextFields();
    }
    
    @Override
    public void paint(Graphics g){
        super.paint(g);
        Renderer.paintImg(jPanel1, sphere, light, cam, g,LIGHT_COLOR);
        //System.out.println("Paint from ModelView");
    }
    
    private void initTextFields(){
        jTextField1.setText(df.format(light.getIA()));
        jTextField2.setText(df.format(light.getIP()));
        jTextField3.setText(df.format(sphere.getKa()));
        jTextField4.setText(df.format(sphere.getKs()));
        jTextField5.setText(df.format(sphere.getKd()));
        jTextField6.setText(df.format(light.getLocation().getX()));
        jTextField7.setText(df.format(light.getLocation().getY()));
        jTextField8.setText(df.format(light.getLocation().getZ()));
        jTextField9.setText(df.format(sphere.getN()));
    }    
    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        iaplus = new javax.swing.JButton();
        iaminus = new javax.swing.JButton();
        ipplus = new javax.swing.JButton();
        ipminus = new javax.swing.JButton();
        kaplus = new javax.swing.JButton();
        kaminus = new javax.swing.JButton();
        ksplus = new javax.swing.JButton();
        ksminus = new javax.swing.JButton();
        kdplus = new javax.swing.JButton();
        kdminus = new javax.swing.JButton();
        kamxplus = new javax.swing.JButton();
        kamyplus = new javax.swing.JButton();
        kamzplus = new javax.swing.JButton();
        kamxminus = new javax.swing.JButton();
        kamyminus = new javax.swing.JButton();
        kamzminus = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jTextField6 = new javax.swing.JTextField();
        jTextField7 = new javax.swing.JTextField();
        jTextField8 = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        jTextField9 = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jComboBox2 = new javax.swing.JComboBox();

        setMaximumSize(new java.awt.Dimension(452, 585));
        setMinimumSize(new java.awt.Dimension(452, 585));

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setPreferredSize(new java.awt.Dimension(500, 400));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 432, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 356, Short.MAX_VALUE)
        );

        jLabel1.setText("Ia");

        jLabel2.setText("Ip");

        jLabel3.setText("Ka");

        jLabel4.setText("Ks");

        jLabel5.setText("Kd");

        jLabel6.setText("Światło x");

        jLabel7.setText("Światło y");

        jLabel8.setText("Światło z");

        iaplus.setText("+");
        iaplus.setActionCommand("Iaplus");
        iaplus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                iaplusActionPerformed(evt);
            }
        });

        iaminus.setText("-");
        iaminus.setActionCommand("iaminus");
        iaminus.setName("iaminus"); // NOI18N
        iaminus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                iaminusActionPerformed(evt);
            }
        });

        ipplus.setText("+");
        ipplus.setActionCommand("ipplus");
        ipplus.setName("ipplus"); // NOI18N
        ipplus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ipplusActionPerformed(evt);
            }
        });

        ipminus.setText("-");
        ipminus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ipminusActionPerformed(evt);
            }
        });

        kaplus.setText("+");
        kaplus.setName("kaplus"); // NOI18N
        kaplus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                kaplusActionPerformed(evt);
            }
        });

        kaminus.setText("-");
        kaminus.setName("kaminus"); // NOI18N
        kaminus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                kaminusActionPerformed(evt);
            }
        });

        ksplus.setText("+");
        ksplus.setName("ksplus"); // NOI18N
        ksplus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ksplusActionPerformed(evt);
            }
        });

        ksminus.setText("-");
        ksminus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ksminusActionPerformed(evt);
            }
        });

        kdplus.setText("+");
        kdplus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                kdplusActionPerformed(evt);
            }
        });

        kdminus.setText("-");
        kdminus.setName("kdminus"); // NOI18N
        kdminus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                kdminusActionPerformed(evt);
            }
        });

        kamxplus.setText("+");
        kamxplus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                kamxplusActionPerformed(evt);
            }
        });

        kamyplus.setText("+");
        kamyplus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                kamyplusActionPerformed(evt);
            }
        });

        kamzplus.setText("+");
        kamzplus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                kamzplusActionPerformed(evt);
            }
        });

        kamxminus.setText("-");
        kamxminus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                kamxminusActionPerformed(evt);
            }
        });

        kamyminus.setText("-");
        kamyminus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                kamyminusActionPerformed(evt);
            }
        });

        kamzminus.setText("-");
        kamzminus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                kamzminusActionPerformed(evt);
            }
        });

        jLabel9.setText("Kolor sfery");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Monochromatyczny", "Żółty", "Magenta", "Cyan", "Czerwony", "Zielony", "Niebieski" }));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jButton1.setBackground(new java.awt.Color(153, 255, 153));
        jButton1.setFont(new java.awt.Font("Tahoma", 1, 11));
        jButton1.setText("Renderuj");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel10.setText("N");

        jTextField9.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextField9FocusLost(evt);
            }
        });

        jLabel11.setText("Kolor światła");

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "<nie uwzględniaj>", "Białe", "Żółte", "Magenta", "Cyan", "Czerwone", "Zielone", "Niebieskie" }));
        jComboBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 432, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel3))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(ipplus, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(iaplus, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(18, 18, 18)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(iaminus, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(ipminus, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(kaplus, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(kaminus, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                        .addComponent(jLabel4)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(ksplus, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                        .addComponent(jLabel5)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(kdplus, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(kdminus, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(ksminus, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addComponent(jLabel10)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addGap(35, 35, 35)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel8))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(kamxplus, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(kamxminus, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(kamyplus, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(kamyminus, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(kamzplus, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(19, 19, 19)
                                        .addComponent(kamzminus, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel9)
                                    .addComponent(jLabel11))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 356, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(iaplus, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(iaminus, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(ipplus, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(ipminus, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7)
                            .addComponent(kamyplus, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(kamyminus, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(kaplus, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(kaminus, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8)
                            .addComponent(kamzminus, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(kamzplus, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(kamxplus, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(kamxminus, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel6)))
                .addGap(17, 17, 17)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(ksplus, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(ksminus, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(kdplus, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(kdminus, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel11)
                            .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1)))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void iaplusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_iaplusActionPerformed

        double ia = light.getIA();
        ia += STEP;
        ia = Renderer.norm0to1(ia);
        light.setIA(ia);
        jTextField1.setText(df.format(ia));
    }//GEN-LAST:event_iaplusActionPerformed

    private void iaminusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_iaminusActionPerformed
        double ia = light.getIA();
        ia -= STEP;
        ia = Renderer.norm0to1(ia);
        light.setIA(ia);
        jTextField1.setText(df.format(ia));
    }//GEN-LAST:event_iaminusActionPerformed

    private void ipplusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ipplusActionPerformed
        double ip = light.getIP();
        ip += STEP;
        ip = Renderer.norm0to1(ip);
        light.setIP(ip);
        jTextField2.setText(df.format(ip));
    }//GEN-LAST:event_ipplusActionPerformed

    private void ipminusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ipminusActionPerformed
        double ip = light.getIP();
        ip -= STEP;
        ip = Renderer.norm0to1(ip);
        light.setIP(ip);
        jTextField2.setText(df.format(ip));
    }//GEN-LAST:event_ipminusActionPerformed

    private void kaplusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_kaplusActionPerformed
        double ka = sphere.getKa();
        ka += STEP;
        ka = Renderer.norm0to1(ka);
        sphere.setKa(ka);
        jTextField3.setText(df.format(ka));
    }//GEN-LAST:event_kaplusActionPerformed

    private void kaminusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_kaminusActionPerformed
        double ka = sphere.getKa();
        ka -= STEP;
        ka = Renderer.norm0to1(ka);
        sphere.setKa(ka);
        jTextField3.setText(df.format(ka));
    }//GEN-LAST:event_kaminusActionPerformed

    private void ksplusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ksplusActionPerformed
        double ks = sphere.getKs();
        ks += STEP;
        ks = Renderer.norm0to1(ks);
        sphere.setKs(ks);
        jTextField4.setText(df.format(ks));
    }//GEN-LAST:event_ksplusActionPerformed

    private void ksminusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ksminusActionPerformed
        double ks = sphere.getKs();
        ks -= STEP;
        ks = Renderer.norm0to1(ks);
        sphere.setKs(ks);
        jTextField4.setText(df.format(ks));
    }//GEN-LAST:event_ksminusActionPerformed

    private void kdplusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_kdplusActionPerformed
        double kd = sphere.getKd();
        kd += STEP;
        kd = Renderer.norm0to1(kd);
        sphere.setKd(kd);
        jTextField5.setText(df.format(kd));
    }//GEN-LAST:event_kdplusActionPerformed

    private void kdminusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_kdminusActionPerformed
        double kd = sphere.getKd();
        kd -= STEP;
        kd = Renderer.norm0to1(kd);
        sphere.setKd(kd);       
        jTextField5.setText(df.format(kd));
        System.out.println(kd);
    }//GEN-LAST:event_kdminusActionPerformed

    private void kamxplusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_kamxplusActionPerformed
        Point3D p = light.getLocation();
        double x = p.getX();
        x += LIGHT_STEP;
        p.setX(x);
        light.setLocation(p);
        jTextField6.setText(df.format(x));
    }//GEN-LAST:event_kamxplusActionPerformed

    private void kamxminusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_kamxminusActionPerformed
        Point3D p = light.getLocation();
        double x = p.getX();
        x -= LIGHT_STEP;
        p.setX(x);
        light.setLocation(p);
        jTextField6.setText(df.format(x));
    }//GEN-LAST:event_kamxminusActionPerformed

    private void kamyplusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_kamyplusActionPerformed
        Point3D p = light.getLocation();
        double y = p.getY();
        y += LIGHT_STEP;
        p.setY(y);
        light.setLocation(p);
        jTextField7.setText(df.format(y));
    }//GEN-LAST:event_kamyplusActionPerformed

    private void kamyminusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_kamyminusActionPerformed
        Point3D p = light.getLocation();
        double y = p.getY();
        y -= LIGHT_STEP;
        p.setY(y);
        light.setLocation(p);
        jTextField7.setText(df.format(y));
    }//GEN-LAST:event_kamyminusActionPerformed

    private void kamzplusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_kamzplusActionPerformed
        Point3D p = light.getLocation();
        double z = p.getZ();
        z += LIGHT_STEP;
        p.setZ(z);
        light.setLocation(p);
        jTextField8.setText(df.format(z));
    }//GEN-LAST:event_kamzplusActionPerformed

    private void kamzminusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_kamzminusActionPerformed
        Point3D p = light.getLocation();
        double z = p.getZ();
        z -= LIGHT_STEP;
        p.setZ(z);
        light.setLocation(p);
        jTextField8.setText(df.format(z));
    }//GEN-LAST:event_kamzminusActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        repaint();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        int index = jComboBox1.getSelectedIndex();
        switch (index) {
            case 0: sphere.setKolor(Color.white); break;
            case 1: sphere.setKolor(Color.yellow); break;
            case 2: sphere.setKolor(Color.magenta); break;
            case 3: sphere.setKolor(Color.cyan); break;
            case 4: sphere.setKolor(Color.red); break;
            case 5: sphere.setKolor(Color.green); break;
            case 6: sphere.setKolor(Color.blue); break;
            default: break;
        }
    }//GEN-LAST:event_jComboBox1ActionPerformed

    private void jTextField9FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextField9FocusLost
        String string = jTextField9.getText();
        if (string.length() != 0){
            try {
            double n = Double.parseDouble(string);
            if (n >= 1)
                sphere.setN(n);
            else
                jTextField9.setText(df.format(sphere.getN()));
            } catch (NumberFormatException nfe) {
                jTextField9.setText(df.format(sphere.getN()));
            }
        } else {
            jTextField9.setText(df.format(sphere.getN()));
        }
    }//GEN-LAST:event_jTextField9FocusLost

    private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox2ActionPerformed
        int index = jComboBox2.getSelectedIndex();
        switch (index) {
            case 0: LIGHT_COLOR = false; break;
            case 1: light.setColor(Color.white); LIGHT_COLOR = true; break;
            case 2: light.setColor(Color.yellow); LIGHT_COLOR = true; break;
            case 3: light.setColor(Color.magenta); LIGHT_COLOR = true; break;
            case 4: light.setColor(Color.cyan); LIGHT_COLOR = true; break;
            case 5: light.setColor(Color.red); LIGHT_COLOR = true; break;
            case 6: light.setColor(Color.green); LIGHT_COLOR = true; break;
            case 7: light.setColor(Color.blue); LIGHT_COLOR = true; break;
            default: break;
        }
    }//GEN-LAST:event_jComboBox2ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton iaminus;
    private javax.swing.JButton iaplus;
    private javax.swing.JButton ipminus;
    private javax.swing.JButton ipplus;
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTextField jTextField8;
    private javax.swing.JTextField jTextField9;
    private javax.swing.JButton kaminus;
    private javax.swing.JButton kamxminus;
    private javax.swing.JButton kamxplus;
    private javax.swing.JButton kamyminus;
    private javax.swing.JButton kamyplus;
    private javax.swing.JButton kamzminus;
    private javax.swing.JButton kamzplus;
    private javax.swing.JButton kaplus;
    private javax.swing.JButton kdminus;
    private javax.swing.JButton kdplus;
    private javax.swing.JButton ksminus;
    private javax.swing.JButton ksplus;
    // End of variables declaration//GEN-END:variables

    MyCamera cam;
    Light light;
    MySphere sphere;
    
    DecimalFormat df = new DecimalFormat("#.#");
    
    public static final double STEP = 0.1;
    public static final double LIGHT_STEP = 10;
    public boolean LIGHT_COLOR = false;
    
}
